﻿using System;
using System.Collections.Generic;
//using System.Linq;
using System.Text;
using NUnit.Framework;
using DBSourceToolsLib;

namespace TestDBSourceToolsLibNUnit
{
    [TestFixture]
    public class TestFileCompare
    {
        private static string STR_BASE_DIR = BaseDirectoryHelper.TestFiles_control_FileCompare;
        [Test]
        public void TestFileCompareCreate()
        {
            
            DBSourceToolsLib.FileComparer.FileComparer oFileComparer = 
                new DBSourceToolsLib.FileComparer.FileComparer("test.txt", "test.txt");
            Assert.IsNotNull(oFileComparer, "Could not create an instance of FileComparer");
        }
        [Test]
        public void TestFilesExist()
        {
            DBSourceToolsLib.FileComparer.FileComparer oFileComparer =
                new DBSourceToolsLib.FileComparer.FileComparer(STR_BASE_DIR + "\\testfiles\\unknown_file_1.txt",
                    STR_BASE_DIR + "\\testfiles\\unknown_file_2.txt");
            Assert.IsNotNull(oFileComparer, "Could not create an instance of FileComparer");
            Assert.IsFalse(oFileComparer.DoFilesExist(), "Files do not exist");
        }

        [Test]
        public void TestFirstFileExists()
        {
            DBSourceToolsLib.FileComparer.FileComparer oFileComparer =
                new DBSourceToolsLib.FileComparer.FileComparer(STR_BASE_DIR + "\\testfiles\\known_file_1.txt",
                    STR_BASE_DIR + "\\testfiles\\unknown_file_2.txt");
            Assert.IsNotNull(oFileComparer, "Could not create an instance of FileComparer");
            Assert.IsFalse(oFileComparer.DoFilesExist(), "Files do not exist");
        }

        [Test]
        public void TestSecondFileExists()
        {
            DBSourceToolsLib.FileComparer.FileComparer oFileComparer =
                new DBSourceToolsLib.FileComparer.FileComparer(STR_BASE_DIR + "\\testfiles\\unknown_file_1.txt",
                    STR_BASE_DIR + "\\testfiles\\known_file_2.txt");
            Assert.IsNotNull(oFileComparer, "Could not create an instance of FileComparer");
            Assert.IsFalse(oFileComparer.DoFilesExist(), "Files do not exist");
        }

        [Test]
        public void TestBothFilesExist()
        {
            DBSourceToolsLib.FileComparer.FileComparer oFileComparer =
                new DBSourceToolsLib.FileComparer.FileComparer(STR_BASE_DIR + "\\testfiles\\known_file_1.txt",
                    STR_BASE_DIR + "\\testfiles\\known_file_2.txt");
            Assert.IsNotNull(oFileComparer, "Could not create an instance of FileComparer");
            Assert.IsTrue(oFileComparer.DoFilesExist(), "Known files are not found");
        }

        [Test]
        public void TestUnequalFiles()
        {
            DBSourceToolsLib.FileComparer.FileComparer oFileComparer =
                new DBSourceToolsLib.FileComparer.FileComparer(STR_BASE_DIR + "\\testfiles\\known_file_1.txt",
                    STR_BASE_DIR + "\\testfiles\\known_file_2.txt");
            Assert.IsNotNull(oFileComparer, "Could not create an instance of FileComparer");
            Assert.IsTrue(oFileComparer.DoFilesExist(), "Known files are not found");
            Assert.IsFalse(oFileComparer.AreFilesEqual(), "Files are found as equal when they are not ");
        }

        [Test]
        public void TestEqualFiles()
        {
            DBSourceToolsLib.FileComparer.FileComparer oFileComparer =
                new DBSourceToolsLib.FileComparer.FileComparer(STR_BASE_DIR + "\\testfiles\\file_1.txt",
                    STR_BASE_DIR + "\\testfiles\\file_2.txt");
            Assert.IsNotNull(oFileComparer, "Could not create an instance of FileComparer");
            Assert.IsTrue(oFileComparer.DoFilesExist(), "Known files are not found");
            Assert.IsTrue(oFileComparer.AreFilesEqual(), "Files are found inequal when they are equal ");
        }

        [Test]
        public void TestUnEqualFiles_ShortFile1()
        {
            DBSourceToolsLib.FileComparer.FileComparer oFileComparer =
                new DBSourceToolsLib.FileComparer.FileComparer(STR_BASE_DIR + "\\testfiles\\file_1.txt",
                    STR_BASE_DIR + "\\testfiles\\file_3.txt");
            Assert.IsNotNull(oFileComparer, "Could not create an instance of FileComparer");
            Assert.IsTrue(oFileComparer.DoFilesExist(), "Known files are not found");
            Assert.IsFalse(oFileComparer.AreFilesEqual(), "Files are found equal when they are not ");
        }
        [Test]
        public void TestUnEqualFiles_ShortFile2()
        {
            DBSourceToolsLib.FileComparer.FileComparer oFileComparer =
                new DBSourceToolsLib.FileComparer.FileComparer(STR_BASE_DIR + "\\testfiles\\file_3.txt",
                    STR_BASE_DIR + "\\testfiles\\file_1.txt");
            Assert.IsNotNull(oFileComparer, "Could not create an instance of FileComparer");
            Assert.IsTrue(oFileComparer.DoFilesExist(), "Known files are not found");
            Assert.IsFalse(oFileComparer.AreFilesEqual(), "Files are found equal when they are not ");
        }
        [Test]
        public void TestUnEqualFiles_TextChange()
        {
            DBSourceToolsLib.FileComparer.FileComparer oFileComparer =
                new DBSourceToolsLib.FileComparer.FileComparer(STR_BASE_DIR + "\\testfiles\\file_1.txt",
                    STR_BASE_DIR + "\\testfiles\\file_4.txt");
            Assert.IsNotNull(oFileComparer, "Could not create an instance of FileComparer");
            Assert.IsTrue(oFileComparer.DoFilesExist(), "Known files are not found");
            Assert.IsFalse(oFileComparer.AreFilesEqual(), "Files are found equal when they are not ");
        }
        [Test]
        public void TestSourceDoesNotExist()
        {
            DBSourceToolsLib.FileComparer.FileComparer oFileComparer =
                new DBSourceToolsLib.FileComparer.FileComparer(STR_BASE_DIR + "\\testfiles\\unknown_file_1.txt",
                    STR_BASE_DIR + "\\testfiles\\unknown_file_2.txt");
            Assert.IsNotNull(oFileComparer, "Could not create an instance of FileComparer");
            Assert.IsFalse(oFileComparer.SourceFileExists(), "Source File do not exist");

        }
    }
}
